var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/Attachment/service.ts
var service_exports = {};
__export(service_exports, {
  attachDelete: () => attachDelete,
  attachDownload: () => attachDownload,
  attachDownloadWaterMarkFile: () => attachDownloadWaterMarkFile,
  attachGetDownloadInfo: () => attachGetDownloadInfo,
  attachGetDownloadWaterMarkInfo: () => attachGetDownloadWaterMarkInfo,
  attachGetWaterMarkContent: () => attachGetWaterMarkContent,
  attachSave: () => attachSave,
  attachUpload: () => attachUpload,
  createZip: () => createZip,
  editCategory: () => editCategory,
  getAttachmentAuditStatus: () => getAttachmentAuditStatus,
  getAttachmentCountBatch: () => getAttachmentCountBatch,
  getBillSourceAttachmentParams: () => getBillSourceAttachmentParams,
  getDownLoadList: () => getDownLoadList,
  getDownloadFileUrl: () => getDownloadFileUrl,
  getPreviewAttachmentList: () => getPreviewAttachmentList,
  getPreviewUrl: () => getPreviewUrl,
  getTaskAttachmentParams: () => getTaskAttachmentParams,
  getTempAttachment: () => getTempAttachment,
  getZipDownloadInfo: () => getZipDownloadInfo,
  mergeChunks: () => mergeChunks,
  richUploadFile: () => richUploadFile,
  saveAttachLabel: () => saveAttachLabel,
  saveTags: () => saveTags,
  shareSave: () => shareSave,
  tableAttachInit: () => tableAttachInit,
  tableAttachSaveRemark: () => tableAttachSaveRemark,
  uploadFile: () => uploadFile
});
module.exports = __toCommonJS(service_exports);
var import_util = require("../../util");
var import_util2 = require("./util");
var adaptorData = (data = []) => {
  return data.map((item) => {
    return {
      approved: 0,
      // 审批字段，未使用
      asrFid: item.fileId,
      // 唯一确定一个附件
      asrName: item.fileName,
      // 附件名称
      asrFlag: item.status,
      // 附件状态, 0 未保存 1 已保存
      asrRemark: item.remark,
      // 备注
      asrSize: item.fileSize,
      // 附件大小,无需转换直接展示
      originFileSize: Number(item.originFileSize || 0),
      // 原始文件大小
      userName: item.uploadName,
      // 上传人
      asrFilldt: item.createTime,
      // 上传时间
      userId: item.createId,
      // 上传人id
      asrTable: item.tag,
      // TODO busiId 跟附件关联的单据的 表名称  asrTable 变为 tag
      asrCode: item.busiId,
      // 唯一确定一个单据
      label: item.label
      // 附件标签
    };
  });
};
var filterUndefined = (data) => {
  const obj = {};
  Object.keys(data).forEach((key) => {
    if (data[key] !== void 0) {
      obj[key] = data[key];
    }
  });
  return obj;
};
var defaultPreviewFileType = ["png", "jpg", "jpeg", "xls", "xlsx", "doc", "docx", "ppt", "pptx", "pdf", "ofd", "mp4"];
async function tableAttachInit(data, cancelId) {
  var _a, _b, _c, _d, _e, _f, _g, _h;
  const { absUrl, url } = (0, import_util2.getFileCenterApiUrl)("/iup-file/tripartite/list");
  const res = await import_util2.customRequest.get({
    absUrl,
    url,
    data: filterUndefined(data),
    cancel: cancelId
  });
  if ((res == null ? void 0 : res.code) === 0) {
    const previewFileType = res.previewFileType ? res.previewFileType.split(".") : defaultPreviewFileType;
    return {
      cursorId: (_a = res == null ? void 0 : res.data) == null ? void 0 : _a.cursorId,
      fileWhiteList: (_c = (_b = res == null ? void 0 : res.data) == null ? void 0 : _b.accept) == null ? void 0 : _c.fileWhiteList,
      fileBlackList: (_e = (_d = res == null ? void 0 : res.data) == null ? void 0 : _d.accept) == null ? void 0 : _e.fileBlackList,
      specialChars: (_g = (_f = res == null ? void 0 : res.data) == null ? void 0 : _f.accept) == null ? void 0 : _g.specialChars,
      previewFileType,
      data: adaptorData((_h = res == null ? void 0 : res.data) == null ? void 0 : _h.data)
    };
  } else {
    throw new Error(res == null ? void 0 : res.message);
  }
}
async function getTempAttachment(data) {
  try {
    const { absUrl, url } = (0, import_util2.getFileCenterApiUrl)("/iup-file/tripartite/list-cursor");
    const res = await import_util2.customRequest.get({
      absUrl,
      url,
      data: filterUndefined(data)
    });
    if ((res == null ? void 0 : res.code) === 0) {
      return adaptorData(res == null ? void 0 : res.data);
    }
  } catch (e) {
    console.log(e);
  }
  return [];
}
async function uploadFile(data) {
  const formData = new FormData();
  Object.keys(data).forEach((key) => {
    if (data[key] !== void 0) {
      if (key === "file") {
        formData.append(key, data[key], data["fileName"]);
      } else {
        formData.append(key, data[key]);
      }
    }
  });
  const { absUrl, url } = (0, import_util2.getFileCenterApiUrl)("/iup-file/tripartite/upload-big-file");
  return await import_util2.customRequest.post({
    absUrl,
    url,
    data: formData
  });
}
async function richUploadFile(data, userToken = import_util.iup.getUser().accessToken) {
  const formData = new FormData();
  Object.keys(filterUndefined(data)).forEach((key) => {
    if (key === "file") {
      formData.append(key, data[key], data["fileName"]);
    } else {
      formData.append(key, data[key]);
    }
  });
  const { absUrl, url } = (0, import_util2.getFileCenterApiUrl)("/iup-file/tripartite/rich-text-upload");
  try {
    return await import_util2.customRequest.post({
      absUrl,
      url,
      headers: { "User-Token": userToken },
      data: formData
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function getPreviewUrl(data) {
  try {
    const { absUrl, url } = (0, import_util2.getFileCenterApiUrl)("/iup-file/tripartite/preview-url");
    return await import_util2.customRequest.get({
      absUrl,
      url,
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function getDownloadFileUrl(data) {
  try {
    const { absUrl, url } = (0, import_util2.getFileCenterApiUrl)("/iup-file/tripartite/download-url");
    return await import_util2.customRequest.get({
      absUrl,
      url,
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function attachUpload(data, dbToken = import_util.iup.getUser().ucode) {
  try {
    return await import_util2.customRequest.post({
      url: "/JFileSrv/file/newUpload",
      headers: { dbToken },
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function attachDelete(data) {
  try {
    const { absUrl, url } = (0, import_util2.getFileCenterApiUrl)("/iup-file/tripartite/del");
    return import_util.iup.request.delete({
      absUrl,
      url,
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function attachSave(data) {
  const { absUrl, url } = (0, import_util2.getFileCenterApiUrl)("/iup-file/tripartite/busi-type-bind");
  return await import_util2.customRequest.body({
    absUrl,
    url,
    data: filterUndefined(data)
  });
}
async function attachGetDownloadInfo(data, dbToken = import_util.iup.getUser().ucode) {
  try {
    return await import_util2.customRequest.get({
      url: "/JFileSrv/reactAttach/getDownloadInfo",
      headers: { dbToken },
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function attachDownload(data, dbToken = import_util.iup.getUser().ucode) {
  try {
    return await import_util2.customRequest.get({
      url: "/JFileSrv/file/download",
      //  url: 'http://10.18.44.11:30599/JFileSrv/file/download',
      //  absUrl: true,
      headers: { dbToken },
      responseType: "arrayBuffer",
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function attachGetDownloadWaterMarkInfo(data, dbToken = import_util.iup.getUser().ucode) {
  try {
    return await import_util2.customRequest.get({
      url: "/JFileSrv/watermark/getWaterMarkFileForReact",
      headers: { dbToken },
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function attachDownloadWaterMarkFile(data, dbToken = import_util.iup.getUser().ucode) {
  try {
    return await import_util2.customRequest.get({
      url: "/JFileSrv/watermark/downloadWaterMarkFile",
      headers: { dbToken },
      responseType: "arrayBuffer",
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function attachGetWaterMarkContent(data, dbToken = import_util.iup.getUser().ucode) {
  try {
    return await import_util2.customRequest.get({
      url: "/JFileSrv/watermark/getWaterMarkContentForReact",
      headers: { dbToken },
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function tableAttachSaveRemark(data) {
  try {
    const { absUrl, url } = (0, import_util2.getFileCenterApiUrl)("/iup-file/tripartite/remark");
    return await import_util.iup.request.put({
      absUrl,
      url,
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function saveAttachLabel(data) {
  try {
    const { absUrl, url } = (0, import_util2.getFileCenterApiUrl)("/iup-file/tripartite/save-update-label");
    return await import_util.iup.request.body({
      absUrl,
      url,
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function getTaskAttachmentParams(data, dbToken = import_util.iup.getUser().ucode) {
  try {
    return await import_util2.customRequest.get({
      url: "/api/WorkFlow3/WorkFlowApp/GetTaskAttachment",
      headers: { Authorization: import_util.iup.getUser().ucode ?? dbToken },
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function getBillSourceAttachmentParams(data, dbToken = import_util.iup.getUser().ucode) {
  try {
    return await import_util2.customRequest.get({
      url: "/api/IMP/EngineApi/GetBillSourceInfo",
      headers: { Authorization: import_util.iup.getUser().ucode ?? dbToken },
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function getDownLoadList(data) {
  try {
    const { absUrl, url } = (0, import_util2.getFileCenterApiUrl)("/iup-file/down-his/list");
    return await import_util2.customRequest.get({
      absUrl,
      url,
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function saveTags(data, dbToken = import_util.iup.getUser().ucode) {
  try {
    return await import_util2.customRequest.post({
      url: "/JFileSrv/reactAttach/docTagsSave",
      headers: { dbToken },
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function shareSave(data, dbToken = import_util.iup.getUser().ucode) {
  try {
    return await import_util2.customRequest.post({
      url: "/JFileSrv/reactAttach/saveAttachShare",
      headers: { dbToken },
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function createZip(data) {
  try {
    const { absUrl, url } = (0, import_util2.getFileCenterApiUrl)("/iup-file/tripartite/zip/task");
    return await import_util2.customRequest.get({
      absUrl,
      url,
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function getZipDownloadInfo(data) {
  try {
    const { absUrl, url } = (0, import_util2.getFileCenterApiUrl)(`/iup-file/tripartite/zip/task/progress/${data.id}`);
    return await import_util2.customRequest.get({
      absUrl,
      url
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function editCategory(data, dbToken = import_util.iup.getUser().ucode) {
  try {
    return await import_util2.customRequest.post({
      url: "/JFileSrv/attachtype/modifyAttachType",
      headers: { dbToken },
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function getPreviewAttachmentList(data, dbToken = import_util.iup.getUser().ucode) {
  try {
    return await import_util2.customRequest.body({
      url: "/JFileSrv/file/previewBatch",
      headers: { dbToken },
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function getAttachmentAuditStatus(data, dbToken = import_util.iup.getUser().ucode) {
  try {
    return await import_util2.customRequest.get({
      url: "/SUP/Attachment/AttachmentGetAuditStatus",
      headers: { dbToken },
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function getAttachmentCountBatch(data, dbToken = import_util.iup.getUser().ucode) {
  try {
    return await import_util2.customRequest.body({
      url: "/fileSrv/record/attachmentRecord/getCountBatch",
      headers: { dbToken },
      data
    });
  } catch (e) {
    console.log(e);
  }
  return null;
}
async function mergeChunks(data) {
  const { absUrl, url } = (0, import_util2.getFileCenterApiUrl)("/iup-file/tripartite/merge");
  const res = await import_util2.customRequest.body({
    absUrl,
    url,
    data
  });
  if (Number(res == null ? void 0 : res.code) === 0) {
    return {
      fileId: res.data.fileId,
      failedChunks: res.data.list
    };
  } else {
    throw new Error(res == null ? void 0 : res.message);
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  attachDelete,
  attachDownload,
  attachDownloadWaterMarkFile,
  attachGetDownloadInfo,
  attachGetDownloadWaterMarkInfo,
  attachGetWaterMarkContent,
  attachSave,
  attachUpload,
  createZip,
  editCategory,
  getAttachmentAuditStatus,
  getAttachmentCountBatch,
  getBillSourceAttachmentParams,
  getDownLoadList,
  getDownloadFileUrl,
  getPreviewAttachmentList,
  getPreviewUrl,
  getTaskAttachmentParams,
  getTempAttachment,
  getZipDownloadInfo,
  mergeChunks,
  richUploadFile,
  saveAttachLabel,
  saveTags,
  shareSave,
  tableAttachInit,
  tableAttachSaveRemark,
  uploadFile
});
